<?php
	if(!defined("IN_APP"))
	{
		exit;
	}
	
	if(!adminpermission('C','C100002'))
	{
		echo '无权查看!';
		exit;
	}
	
	$method = getParam('m','request','list');
	
	$parm = requestArrayParm($_REQUEST);
	
	if($method == 'list')
	{
		
		unset($query);
		if($parm['type'] == '1')
		{
			//昨天
			$query['start'] = strtotime(date("Y-m-d"))-86400;
			$query['end'] = $query['start']+86399;
		}
		
		if($parm['type'] == '2')
		{
			//今天
			$query['start'] = strtotime(date("Y-m-d"));
			$query['end'] = $query['start']+86399;
		}
		
		if($parm['type'] == '3')
		{
			//前三天
			$query['start'] = strtotime(date("Y-m-d"))-3*86400;
			$query['end'] = strtotime(date("Y-m-d"))-1;
		}
		
		if($parm['type'] == '4')
		{
			//前七天(7天)
			$query['start'] = strtotime(date("Y-m-d"))-7*86400;
			$query['end'] = strtotime(date("Y-m-d"))-1;
		}
		
		if($parm['type'] == '5')
		{
			//前一月(30天)
			$query['start'] = strtotime(date("Y-m-d"))-30*86400;
			$query['end'] = strtotime(date("Y-m-d"))-1;
		}
		
		if($parm['type'] == '6')
		{
			//选择时间段
			$query['start'] = strtotime($parm['start']);
			$query['end'] = strtotime($parm['end']);
		}
		
		if(empty($query['start']) && empty($query['end']))
		{
			$query['start'] = strtotime(date("Y-m-d"));
			$query['end'] = $query['start']+86399;
		}
		
		$sort['id'] = 'desc';
		$resData = _ChanPin::getChanPinList(array(), array(),$sort);
		
		foreach ($resData as $key => $value)
		{
			$query['pid'] = $value['id'];
			$value['tongji'] = _Tongji_log::getChanpin_tongji($query);
			$list[] = $value;
		}
		
		include renderTemplate('admin/tongji/chanpin_list');
	}
	
	if($method == 'detail')
	{
		if($parm['pid'])
		{
			unset($where,$data);
			$where['id'] = $parm['pid'];
			$chanpin = _ChanPin::getChanPinInfo($where);
			
			if($chanpin)
			{
				$pagetitle = $chanpin['name'];
				unset($wheres);
				$wheres['pid'] = $chanpin['id'];
				$sort['sort'] = 'desc';
				$resData = _ChanPin::getChanPin_ItemList($wheres, array(),$sort);
				
				unset($query);
				if($parm['type'] == '1')
				{
					//昨天
					$query['start'] = strtotime(date("Y-m-d"))-86400;
					$query['end'] = $query['start']+86399;
				}
				
				if($parm['type'] == '2')
				{
					//今天
					$query['start'] = strtotime(date("Y-m-d"));
					$query['end'] = $query['start']+86399;
				}
				
				if($parm['type'] == '3')
				{
					//前三天
					$query['start'] = strtotime(date("Y-m-d"))-3*86400;
					$query['end'] = strtotime(date("Y-m-d"))-1;
				}
				
				if($parm['type'] == '4')
				{
					//前七天(7天)
					$query['start'] = strtotime(date("Y-m-d"))-7*86400;
					$query['end'] = strtotime(date("Y-m-d"))-1;
				}
				
				if($parm['type'] == '5')
				{
					//前一月(30天)
					$query['start'] = strtotime(date("Y-m-d"))-30*86400;
					$query['end'] = strtotime(date("Y-m-d"))-1;
				}
				
				if($parm['type'] == '6')
				{
					//选择时间段
					$query['start'] = strtotime($parm['start']);
					$query['end'] = strtotime($parm['end']);
				}
				
				if(empty($query['start']) && empty($query['end']))
				{
					$query['start'] = strtotime(date("Y-m-d"));
					$query['end'] = $query['start']+86399;
				}
				
				foreach ($resData as $key => $value)
				{
					$query['iid'] = $value['id'];
					$value['tongji'] = _Tongji_log::getChanpinItem_tongji($query);
					$list[] = $value;
				}
				
			}
			else
			{
				header("Location:".SITE_URL.'admin.php?a=chanpinC');
			}
		}
		else
		{
			header("Location:".SITE_URL.'admin.php?a=chanpinC');
		}
		
		include renderTemplate('admin/tongji/chanpin_detail');
	}
	